import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/pages/Login.vue'
import Home from '@/pages/home/index.vue'

const router = createRouter({
    // 配置路由模式
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            redirect: '/login'
        },
        {
            // 匹配地址
            path: "/login",
            // 地址匹配的组件
            component: Login
        },
        {
            path: "/home",
            component: Home,
            redirect: "/home/welcome",
            children: [
                {
                    // path: "/home/welcome"
                    path: "welcome",
                    component: () => import('@/pages/home/welcome.vue')
                },
                {
                    path: "adminCar",
                    component: () => import('@/pages/home/adminCar.vue')
                },
                {
                    path: "adminLines",
                    component: () => import('@/pages/home/adminLines.vue')
                },
                {
                    path: "adminStation",
                    component: () => import('@/pages/home/adminStation.vue')
                },
                {
                    path: "adminTickets",
                    component: () => import('@/pages/home/adminTickets.vue')
                },
                {
                    path: "adminOrder",
                    component: () => import('@/pages/home/adminOrder.vue')
                },
                {
                    path: "orbitMonitoring",
                    component: () => import('@/pages/home/orbitMonitoring.vue')
                },
                {
                    path: "talk",
                    component: () => import('@/pages/home/talk.vue')
                }
            ]
        },
        {
            path: "/:catchAll(.*)",
            component: () => import('@/pages/404.vue')
        }
    ]
})

router.beforeEach((to, from, next) => {
    // if (to.path !== '/login') {
    //     if (sessionStorage.getItem("token")) {
    //         next()
    //     } else {
    //         next('/login')
    //     }
    // } else {
    //     next()
    // }
    next()
})

export default router

